var str = "";


function initDate(){
    var now=new Date();
    now.setDate(now.getDate()+1);
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var MyDate = now.getFullYear()+"-"+(month)+"-"+(day);
    $(document.getElementById("tdate")).val(MyDate);
}
function checkDate(){
    var tdate=document.getElementById("tdate").value;
    ajaxCall("Post","../TeamExamServlet?method=checkDate&date="+tdate,checkResult);
}
function setQuestion(){
    var tdate=document.getElementById("tdate").value;
    var tableId = document.getElementById("tques");
    var classId=document.getElementById("s1").value;
    var trs = tableId.rows;
    if(trs.length==1){
        alert("提交内容为空!!!");
        return;
    }
    for(var i = 1, len = trs.length ; i < len; i++) {
        var id = trs[i].cells[0].innerHTML;
        str += id + ",";


    }
    ajaxCall("POST", "../TeamExamServlet?method=setQuestion&tquestionId=" + str + "&tdate=" + tdate + "&classId=" + classId, getResult);
}
function checkResult(res) {
    var obj=JSON.parse(res);
    if(obj){
        setQuestion();
    }
    else{
        alert("该日期已发布过结对作业！请更换日期");
    }
}




function getResult(res) {
    var obj = JSON.parse(res);
    if(obj){
        alert("添加成功！");
        location.reload();
    }else{
        alert("添加失败！");
    }
}
